package com.googlecode.continuity.plugin.gwtext.client;

import java.util.ArrayList;

import com.google.gwt.user.client.ui.Composite;

/**
 * RatingControl
 *
 * @author Peter Schmitt <aragos@aragos.de>
 */
public abstract class RatingControl extends Composite implements SourcesRatingEvents {
  private ArrayList listeners;

  public void addRatingListener(RatingListener listener) {
    if (listeners == null) {
      listeners = new ArrayList();
    }
    listeners.add(listener);
  }

  public void removeRatingListener(RatingListener listener) {
    if (listeners == null) {
      return;
    }
    listeners.remove(listener);
  }

  protected void fireRating(float rating) {
    if (listeners == null) {
      return;
    }
    for (int i = 0; i < listeners.size(); i++) {
      ((RatingListener) listeners.get(i)).onRated(this, rating);
    }
  }
}
